package com.he.controller;

import com.he.mapper.BookstopMapper;
import com.he.pojo.Bookstop;
import com.he.service.BookstopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author: He
 * @data 2025/10/17 14:03
 */
@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    public BookstopService service;
    @Autowired
    public BookstopMapper dao;

    @RequestMapping("/select")
    public String select(Model model) {

        List<Bookstop> bookstops = service.selectAll();

        model.addAttribute("bookstops", bookstops);

        return "book_manager";

    }

    @RequestMapping("/insert")
    public String insert(Model model, Bookstop bookstop) {
        int i = service.insert(bookstop);
        return "redirect:/book/select";

    }

    @RequestMapping("/getbookByid")
    public String getbookByid(Model model,int id) {


        Bookstop byId = service.selectById(id);

        model.addAttribute("bookstop", byId);

        return "book_e";

    }

    @RequestMapping("/update")
    public String update(Model model, Bookstop bookstop) {


        service.update(bookstop);

        return "redirect:/book/select";

    }

    @RequestMapping("/delete")
    public String delete(Model model, int id) {

        service.delete(id);

        return "redirect:/book/select";

    }



}
